﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gift.DAL;
using Gift.Model;

namespace WebSite.cn
{
    public partial class ValidateCard : BasePage
    {


        readonly Card theCard = new Card();
        readonly OrderAccount theOrderAccount = new OrderAccount();
        readonly Shoppro theShoppro = new Shoppro();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
        }


        protected void txtSubmit_Click(object sender, EventArgs e)
        {
            if (string.Compare(this.txtValidate.Text.Trim(), Session["checkCode"].ToString()) != 0)
            {
                Response.Write("<script>alert('验证码不正确！请重新输入！');window.location.href='ValidateCard.aspx';</script>");
            }

            dbCard oCard;
            oCard = theCard.GetModel(this.txtCardCode.Text.Trim(), this.txtPassword.Text.Trim());
            if (oCard != null)
            {
                string tempIsHavePop = base.IsHavePop;
                Session.Clear();
                base.IsHavePop = tempIsHavePop == null ? null : tempIsHavePop.ToString();
                DALCardType theCardType = new DALCardType();
                DALProfessionAreaType theProfessionAreaType = new DALProfessionAreaType();
                tbCardType oCardType = new tbCardType();
                tbProfessionAreaType oProfessionAreaType = new tbProfessionAreaType();
                oCardType =  theCardType.GetModel(oCard.cardtypeId);
                oProfessionAreaType = theProfessionAreaType.GetModel(oCardType.ProfessionAreaTypeId);
                this.lblMessage.Text = "<div style='width:100%;text-align:left;line-height:20px;'> 卡片类别:" + oCardType.Name + ";<br/>所属专区:" + oProfessionAreaType.Name + ";<br/>卡内金额:" + oCard.cardprice.ToString()
                                      + " <br/> 专区有效时间：" + oCard.StartTime.ToString("yyyy-MM-dd") + " 至" + oCard.endtime.ToString("yyyy-MM-dd") + ";";
           
                    this.lblMessage.Text =   this.lblMessage.Text
                                              + " <br/> 礼品商城有效时间为：" + oCard.StartTimeII.AddDays(1).ToString("yyyy-MM-dd") + " 到 " + oCard.lasttime.ToString("yyyy-MM-dd"); 
         
                                     
                if (oCard.states == 0)
                {
                    this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡还未激活，请先开卡后才能使用！";
                }
                else if (oCard.states == 2)
                {
                    this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡已被使用！";
                }
                else if (oCard.states == 3)
                {
                    this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡已失效！";
                }
                else if (oCard.states == 4)
                {
                    this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡还未激活,请先开卡后才能使用！";
                }
                else if (oCard.endtime < DateTime.Now)
                {
                    if (oCard.lasttime >= DateTime.Now)
                    {
                        this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡的专区有效时间已过,只能到礼品商城兑换商品！";
                    }
                    else
                    {
                        this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡已失效！";
                    }
                }
                else if (oCard.states == 1)
                {

                    this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡可以正常使用！";

                }
                else
                {
                    this.lblMessage.Text = this.lblMessage.Text + "<br/>该卡已被使用！";
                }
                this.lblMessage.Text = this.lblMessage.Text + "</div>";
            }
            else
            {
                this.lblMessage.Text = "卡号或密码不正确！";
            }
        }
    }
}